package implementierung;

import schnittstellen.IList;
import schnittstellen.IListElement;
import schnittstellen.IQueue;

public class Queue implements IQueue
{

    private int size;

    private IList dvl;

    public Queue()
    {
        super();
        this.size = 0;
        this.dvl = new List();
    }

    @Override
    public IList getDVL()
    {
        return dvl;
    }

    @Override
    public int getSize()
    {
        IListElement current = dvl.getHead().getSuccessor();
        size = 0;
        while (current != null)
        {
            current = current.getSuccessor();
            size++;
        }
        return size;
    }

    @Override
    public boolean isEmpty()
    {
        if (getSize() > 0)
        {
            return false;
        }
        return true;
    }

    @Override
    public boolean isFull()
    {
        return (getSize() == 7);
    }

    @Override
    public int dequeue()
    {
        if (isEmpty())
        {
            return -1;
        }
        else
        {
            int element = dvl.getElementAt(getSize()).getValue();
            dvl.deleteFirstOf(dvl.getElementAt(getSize()));
            return element;
        }
    }

    @Override
    public void enqueue(int value)
    {
        if (value >= 0 && !(isFull()))
        {
            dvl.insertAtPos(1, new ValueElement("", value));
        }
    }

    @Override
    public int front()
    {
        if (getSize() > 0)
        {
            return dvl.getElementAt(getSize()).getValue();
        }
        return -1;
    }

}
